bitkeeper revision 1.1159.53.11 (412f3a03Su4nmVv7scE_x2v_aEs7fA)
authorkaf24@freefall.cl.cam.ac.uk <kaf24@freefall.cl.cam.ac.uk>
Fri, 27 Aug 2004 13:41:23 +0000 (13:41 +0000)
committerkaf24@freefall.cl.cam.ac.uk <kaf24@freefall.cl.cam.ac.uk>
Fri, 27 Aug 2004 13:41:23 +0000 (13:41 +0000)
Change timestamp format exported by Xen. Now we provide all 64 bits
of the processor's TSC.

linux-2.4.27-xen-sparse/arch/xen/kernel/time.c
linux-2.6.8.1-xen-sparse/arch/xen/i386/kernel/time.c
linux-2.6.8.1-xen-sparse/arch/xen/i386/kernel/timers/timer_tsc.c
xen/arch/x86/time.c
xen/include/hypervisor-ifs/arch-x86_32.h
xen/include/hypervisor-ifs/arch-x86_64.h

index 23aac6c308c5fe8de7da17fd8d96268592530eda..a2ffce30393a545e4ed43b572d4867eb75c4000d 100644 (file)
@@ -214,7 +214,8 @@ static void __get_time_values_from_xen(void)
         rmb();
         shadow_tv.tv_sec    = HYPERVISOR_shared_info->wc_sec;
         shadow_tv.tv_usec   = HYPERVISOR_shared_info->wc_usec;
-        shadow_tsc_stamp    = HYPERVISOR_shared_info->tsc_timestamp.tsc_bits;
+        shadow_tsc_stamp    = 
+            (u32)(HYPERVISOR_shared_info->tsc_timestamp >> rdtsc_bitshift);
         shadow_system_time  = HYPERVISOR_shared_info->system_time;
         rmb();
     }
@@ -604,6 +605,7 @@ void __init time_init(void)
 {
     unsigned long long alarm;
     u64 __cpu_khz, cpu_freq, scale, scale2;
+    unsigned int cpu_ghz;
 
     __cpu_khz = HYPERVISOR_shared_info->cpu_freq;
     do_div(__cpu_khz, 1000);
@@ -615,8 +617,11 @@ void __init time_init(void)
     xtime.tv_usec = HYPERVISOR_shared_info->wc_usec;
     processed_system_time = shadow_system_time;
 
-    rdtsc_bitshift      = HYPERVISOR_shared_info->tsc_timestamp.tsc_bitshift;
-    cpu_freq            = HYPERVISOR_shared_info->cpu_freq;
+    cpu_freq = HYPERVISOR_shared_info->cpu_freq;
+
+    cpu_ghz = do_div(cpu_freq, 1000000000UL);
+    for ( rdtsc_bitshift = 0; cpu_ghz != 0; rdtsc_bitshift++, cpu_ghz >>= 1 )
+        continue;
 
     scale = 1000000LL << (32 + rdtsc_bitshift);
     do_div(scale, (u32)cpu_freq);
index fbd059a5f7adc358217151b59534ba13050c81a0..10562570a8c901abc34d69ad213a94bb45f8862c 100644 (file)
@@ -160,7 +160,7 @@ static void __get_time_values_from_xen(void)
                rmb();
                shadow_tv.tv_sec    = s->wc_sec;
                shadow_tv.tv_usec   = s->wc_usec;
-               shadow_tsc_stamp    = s->tsc_timestamp.tsc_bits;
+               shadow_tsc_stamp    = (u32)s->tsc_timestamp;
                shadow_system_time  = s->system_time;
                rmb();
        }
index 05e370f9325f91c71f1cb89df6ac8028b18876d3..7348d2a08151f17eac2110fb60a1017fdc8a5f6f 100644 (file)
@@ -78,7 +78,6 @@ static int count2; /* counter for mark_offset_tsc() */
  */
 static unsigned long fast_gettimeoffset_quotient;
 
-unsigned int rdtsc_bitshift;
 extern u32 shadow_tsc_stamp;
 extern u64 shadow_system_time;
 
@@ -91,7 +90,7 @@ static unsigned long get_offset_tsc(void)
        rdtsc(eax,edx);
 
        /* .. relative to previous jiffy (32 bits is enough) */
-       eax -= (shadow_tsc_stamp << rdtsc_bitshift) & 0xffffffff;
+       eax -= shadow_tsc_stamp;
 
        /*
         * Time offset = (tsc_low delta) * fast_gettimeoffset_quotient
@@ -119,7 +118,7 @@ static unsigned long long monotonic_clock_tsc(void)
        /* atomically read monotonic base & last_offset */
        do {
                seq = read_seqbegin(&monotonic_lock);
-               last_offset = monotonic_offset << rdtsc_bitshift;
+               last_offset = monotonic_offset;
                base = monotonic_base;
        } while (read_seqretry(&monotonic_lock, seq));
 
@@ -349,8 +348,6 @@ static int __init init_tsc(char* override)
                    "0" (eax), "1" (edx));
        }
 
-       rdtsc_bitshift = HYPERVISOR_shared_info->tsc_timestamp.tsc_bitshift;
-
        set_cyc2ns_scale(cpu_khz/1000);
 
        rdtscll(alarm);
index dfe20e415d33faad6fe45a132d24d7caead8c648..48b2ce97622b02499dd12880a22a6c438e00af82 100644 (file)
@@ -44,15 +44,14 @@ static unsigned int    rdtsc_bitshift;  /* Which 32 bits of TSC do we use?   */
 static u64             cpu_freq;        /* CPU frequency (Hz)                */
 static u32             st_scale_f;      /* Cycles -> ns, fractional part     */
 static u32             st_scale_i;      /* Cycles -> ns, integer part        */
-static u32             tsc_irq;         /* CPU0's TSC at last 'time update'  */
+static u32             shifted_tsc_irq; /* CPU0's TSC at last 'time update'  */
+static u64             full_tsc_irq;    /* ...ditto, but all 64 bits         */
 static s_time_t        stime_irq;       /* System time at last 'time update' */
 static unsigned long   wc_sec, wc_usec; /* UTC time at last 'time update'.   */
 static rwlock_t        time_lock = RW_LOCK_UNLOCKED;
 
 static void timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
-    u64 full_tsc;
-
     write_lock_irq(&time_lock);
 
 #ifdef CONFIG_X86_IO_APIC
@@ -71,8 +70,8 @@ static void timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
      * Updates TSC timestamp (used to interpolate passage of time between
      * interrupts).
      */
-    rdtscll(full_tsc);
-    tsc_irq = (u32)(full_tsc >> rdtsc_bitshift);
+    rdtscll(full_tsc_irq);
+    shifted_tsc_irq = (u32)(full_tsc_irq >> rdtsc_bitshift);
 
     /* Update jiffies counter. */
     (*(unsigned long *)&jiffies)++;
@@ -243,7 +242,7 @@ static inline u64 get_time_delta(void)
 
     rdtscll(tsc);
     low = (u32)(tsc >> rdtsc_bitshift);
-    delta_tsc = (s32)(low - tsc_irq);
+    delta_tsc = (s32)(low - shifted_tsc_irq);
     if ( unlikely(delta_tsc < 0) ) delta_tsc = 0;
     delta = ((u64)delta_tsc * st_scale_f);
     delta >>= 32;
@@ -285,8 +284,7 @@ void update_dom_time(shared_info_t *si)
     wmb();
 
     si->cpu_freq       = cpu_freq;
-    si->tsc_timestamp.tsc_bitshift = rdtsc_bitshift;
-    si->tsc_timestamp.tsc_bits     = tsc_irq;
+    si->tsc_timestamp  = full_tsc_irq;
     si->system_time    = stime_irq;
     si->wc_sec         = wc_sec;
     si->wc_usec        = wc_usec;
@@ -328,7 +326,6 @@ void do_settime(unsigned long secs, unsigned long usecs, u64 system_time_base)
 int __init init_xen_time()
 {
     u64      scale;
-    u64      full_tsc;
     unsigned int cpu_ghz;
 
     cpu_ghz = (unsigned int)(cpu_freq / 1000000000ULL);
@@ -341,9 +338,9 @@ int __init init_xen_time()
     st_scale_i = scale >> 32;
 
     /* System time ticks from zero. */
-    rdtscll(full_tsc);
+    rdtscll(full_tsc_irq);
     stime_irq = (s_time_t)0;
-    tsc_irq   = (u32)(full_tsc >> rdtsc_bitshift);
+    shifted_tsc_irq = (u32)(full_tsc_irq >> rdtsc_bitshift);
 
     /* Wallclock time starts as the initial RTC time. */
     wc_sec  = get_cmos_time();
index 04edd474eaaec691acf1fa4d2538c3d52aacbc3a..91a111bd92d078d99b13b80d82030245b250a83f 100644 (file)
@@ -104,10 +104,7 @@ typedef struct
     unsigned long ss;
 } PACKED execution_context_t;
 
-typedef struct {
-    u32  tsc_bits;      /* 0: 32 bits read from the CPU's TSC. */
-    u32  tsc_bitshift;  /* 4: 'tsc_bits' uses N:N+31 of TSC.   */
-} PACKED tsc_timestamp_t; /* 8 bytes */
+typedef u64 tsc_timestamp_t; /* RDTSC timestamp */
 
 /*
  * The following is all CPU context. Note that the i387_ctxt block is filled 
index 701084cec647ff56772c70d33b24af993a5398aa..7ac8cf8a73e265e50c66ee2f6a484aa95792dacf 100644 (file)
@@ -100,14 +100,7 @@ typedef struct
     unsigned long ss;
 } PACKED execution_context_t;
 
-/*
- * NB. This may become a 64-bit count with no shift. If this happens then the 
- * structure size will still be 8 bytes, so no other alignments will change.
- */
-typedef struct {
-    u32  tsc_bits;      /* 0: 32 bits read from the CPU's TSC. */
-    u32  tsc_bitshift;  /* 4: 'tsc_bits' uses N:N+31 of TSC.   */
-} PACKED tsc_timestamp_t; /* 8 bytes */
+typedef u64 tsc_timestamp_t; /* RDTSC timestamp */
 
 /*
  * The following is all CPU context. Note that the i387_ctxt block is filled